package com.wang.ssm.service;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wang.ssm.mapper.*;
import com.wang.ssm.pojo.User;
import com.wang.ssm.pojo.UserType;
import com.wang.ssm.pojo.vo.ExamVo;
import com.wang.ssm.pojo.vo.RoomVo;
import com.wang.ssm.pojo.vo.StudentVo;
import com.wang.ssm.pojo.vo.TeacherVo;
import com.wang.ssm.util.Result;
import com.wang.ssm.util.StatusCode;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 王瑞杰
 * date 2023/10/18
 */
@Service
public class StuServiceImpl implements StuService{
    @Resource
    private StudentMapper studentMapper;
    @Resource
    private TeacherMapper teacherMapper;
    @Resource
    private ExamMapper examMapper;
    @Resource
    private RoomMapper roomMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private UserTypeMapper typeMapper;
    @Override
    public PageInfo<StudentVo> findAll(Integer offset,Integer pageSize,String sname) {
        PageHelper.startPage(offset,pageSize);
        return new PageInfo<>(studentMapper.findAll(sname));
    }

    @Override
    public PageInfo<TeacherVo> findtea(Integer offter,Integer  count) {
        PageHelper.startPage(offter,count);
        return new PageInfo<>(teacherMapper.findtea());
    }

    @Override
    public List<ExamVo> findex() {
        return examMapper.findex();
    }

    @Override
    public boolean save(StudentVo student) {
        if(student.getSid()==null){
            return studentMapper.add(student)==1;
        }
        return studentMapper.update(student)==1;
    }

    @Override
    public Result delete(String[] arr) {
        return teacherMapper.deleteByBath(arr)>=1 ?
                new Result<>(StatusCode.OK,"删除成功",true):
                new Result<>(StatusCode.ERROR,"删除失败",false);
    }

    @Override
    public List<RoomVo> findroom() {
        return roomMapper.findroom();
    }

    @Override
    public User login(String username, String password) {
        return userMapper.login(username,password);
    }

    @Override
    public List<User> finduser() {
        return userMapper.finduser();
    }

    @Override
    public boolean saveuser(User user) {
        if(user.getUid()==null){
            return userMapper.adduser(user)==1;
        }
        return userMapper.upuser(user)>=1;
    }

    @Override
    public boolean uppass(User user) {
        return userMapper.uppass(user)==1;
    }

    @Override
    public User findById(String uid) {
        return userMapper.findById(uid);
    }

    @Override
    public List<UserType> findType() {
        return typeMapper.findType();
    }
}
